<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>易点秒杀-正品秒杀！</title>
	<link rel="icon" href="./img/favicon.ico">

	<!-- 引入样式 -->
	<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

	<link rel="stylesheet" type="text/css" href="./css/all.css" />
	<link rel="stylesheet" type="text/css" href="./css/pages-seckill-index.css" />
</head>

<body>
<div id="app">
	<!-- 头部栏位 -->
	<!--页面顶部-->
	<div id="nav-bottom">
		<!--顶部-->
		<div class="nav-top">
			<div class="top">
				<div class="py-container">
					<div class="shortcut">
						<ul class="fl">
							<li class="f-item">易点欢迎您！</li>
							<li class="f-item">请
								<a href="login.html" target="_blank">登录</a>
								<span>
									<a href="register.html" target="_blank">免费注册</a>
								</span>
							</li>
						</ul>
						<div class="fr typelist">
							<ul class="types">
								<li class="f-item">
									<span>我的订单</span>
								</li>

								<li class="f-item">
									<span>
										<a href="cart.html" target="_blank">我的购物车</a>
									</span>
								</li>
								<li class="f-item">
									<span>
										<a href="home.html" target="_blank">我的易点</a>
									</span>
								</li>
								<li class="f-item">
									<span>易点会员</span>
								</li>
								<li class="f-item">
									<span>企业采购</span>
								</li>
								<li class="f-item">
									<span>关注易点</span>
								</li>
								<li class="f-item">
									<span>
										<a href="cooperation.html" target="_blank">合作招商</a>
									</span>
								</li>
								<li class="f-item">
									<span>
										<a href="shoplogin.html" target="_blank">商家后台</a>
									</span>
								</li>
								<li class="f-item">
									<span>网站导航</li>
							</ul>
						</div>

					</div>
				</div>
			</div>

			<!--头部-->
			<div class="header">
				<div class="py-container">
					<div class="yui3-g Logo">
						<div class="yui3-u Left logoArea">
							<!--<a class="logo-bd" title="易点" href="index.html" target="_blank"></a>-->
						</div>
						<div class="yui3-u Rit searchArea">
							<div class="search">
								<form action="" class="sui-form form-inline">
									<!--searchAutoComplete-->
									<div class="input-append">
										<input type="text" id="autocomplete" class="input-error input-xxlarge" />
										<button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
									</div>
								</form>
							</div>
						</div>

					</div>

				</div>
			</div>
		</div>
	</div>


	<div class="py-container index">
		<!--banner-->
		<div class="banner">
			<img src="./img/_/banner.png" class="img-responsive" alt="">
		</div>
		<!--秒杀时间-->
		<div class="sectime">
			<div v-for="(menu,index) in datemenus" :class="['item-time',index==cdate?'active':'']" @click="cdate=index;searchGoodsList(menu)">
				<div class="time-clock">{{menu|dateFilter('HH:mm')}}</div>
				<div class="time-state-on" v-if="index==0">
					<span class="on-text">快抢中</span>
					<span class="on-over">距离结束：{{timeFormat(alltimes[index])}}</span>
				</div>
				<div class="time-state-on" v-if="index>0">
					<span class="on-text">即将开抢</span>
					<span class="on-over">距离开始：{{timeFormat(alltimes[index])}}</span>
				</div>
			</div>
		</div>
		<!--商品列表-->
		<div class="goods-list">
			<ul class="seckill" id="seckill">
				<li class="seckill-item" v-for="item in goodslist" :key="item">
					<div class="pic">
						<img :src="item.smallPic" alt=''>
					</div>
					<div class="intro">
						<span>{{item.title}}</span>
					</div>
					<div class='price'>
						<b class='sec-price'>￥{{item.costPrice}}</b>
						<b class='ever-price'>￥{{item.price}}</b>
					</div>
					<div class='num'>
						<div>已售{{item.num-item.stockCount}}</div>
						<div class='progress'>
							<div class='sui-progress progress-danger'>
								<span :style="'width:'+ ((item.num-item.stockCount)/item.num)*100 +'%;'" class='bar'></span>
							</div>
						</div>
						<div>剩<b class='owned'>{{item.stockCount}}</b>件</div>
					</div>
					<a class='sui-btn btn-block btn-buy' :href='targetDetailPage(item.startTime,item.wid)' target='_blank'>抢购</a>
				</li>
			</ul>
		</div>
		<div class="cd-top">
			<div class="top">
				<img src="./img/_/gotop.png" />
				<b>TOP</b>
			</div>
			<div class="code" id="code">
				<span>
					<img src="./img/_/code.png" />
				</span>
			</div>
			<div class="erweima">
				<img src="./img/_/erweima.jpg" alt="">
				<s></s>
			</div>
		</div>
	</div>

	<!--回到顶部-->

	<!-- 底部栏位 -->
	<!--页面底部-->
	<div class="clearfix footer">
		<div class="py-container">
			<div class="footlink">
				<div class="Mod-service">
					<ul class="Mod-Service-list">
						<li class="grid-service-item intro  intro1">

							<i class="serivce-item fl"></i>
							<div class="service-text">
								<h4>正品保障</h4>
								<p>正品保障，提供发票</p>
							</div>

						</li>
						<li class="grid-service-item  intro intro2">

							<i class="serivce-item fl"></i>
							<div class="service-text">
								<h4>正品保障</h4>
								<p>正品保障，提供发票</p>
							</div>

						</li>
						<li class="grid-service-item intro  intro3">

							<i class="serivce-item fl"></i>
							<div class="service-text">
								<h4>正品保障</h4>
								<p>正品保障，提供发票</p>
							</div>

						</li>
						<li class="grid-service-item  intro intro4">

							<i class="serivce-item fl"></i>
							<div class="service-text">
								<h4>正品保障</h4>
								<p>正品保障，提供发票</p>
							</div>

						</li>
						<li class="grid-service-item intro intro5">

							<i class="serivce-item fl"></i>
							<div class="service-text">
								<h4>正品保障</h4>
								<p>正品保障，提供发票</p>
							</div>

						</li>
					</ul>
				</div>
				<div class="clearfix Mod-list">
					<div class="yui3-g">
						<div class="yui3-u-1-6">
							<h4>购物指南</h4>
							<ul class="unstyled">
								<li>购物流程</li>
								<li>会员介绍</li>
								<li>生活旅行/团购</li>
								<li>常见问题</li>
								<li>购物指南</li>
							</ul>

						</div>
						<div class="yui3-u-1-6">
							<h4>配送方式</h4>
							<ul class="unstyled">
								<li>上门自提</li>
								<li>211限时达</li>
								<li>配送服务查询</li>
								<li>配送费收取标准</li>
								<li>海外配送</li>
							</ul>
						</div>
						<div class="yui3-u-1-6">
							<h4>支付方式</h4>
							<ul class="unstyled">
								<li>货到付款</li>
								<li>在线支付</li>
								<li>分期付款</li>
								<li>邮局汇款</li>
								<li>公司转账</li>
							</ul>
						</div>
						<div class="yui3-u-1-6">
							<h4>售后服务</h4>
							<ul class="unstyled">
								<li>售后政策</li>
								<li>价格保护</li>
								<li>退款说明</li>
								<li>返修/退换货</li>
								<li>取消订单</li>
							</ul>
						</div>
						<div class="yui3-u-1-6">
							<h4>特色服务</h4>
							<ul class="unstyled">
								<li>夺宝岛</li>
								<li>DIY装机</li>
								<li>延保服务</li>
								<li>品优购E卡</li>
								<li>品优购通信</li>
							</ul>
						</div>
						<div class="yui3-u-1-6">
							<h4>帮助中心</h4>
							<img src="./img/wx_cz.jpg">
						</div>
					</div>
				</div>
				<div class="Mod-copyright">
					<ul class="helpLink">
						<li>关于我们
							<span class="space"></span>
						</li>
						<li>联系我们
							<span class="space"></span>
						</li>
						<li>关于我们
							<span class="space"></span>
						</li>
						<li>商家入驻
							<span class="space"></span>
						</li>
						<li>营销中心
							<span class="space"></span>
						</li>
						<li>友情链接
							<span class="space"></span>
						</li>
						<li>关于我们
							<span class="space"></span>
						</li>
						<li>营销中心
							<span class="space"></span>
						</li>
						<li>友情链接
							<span class="space"></span>
						</li>
						<li>关于我们</li>
					</ul>
					<p>地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</p>
					<p>京ICP备08001421号京公网安备110108007702</p>
				</div>
			</div>
		</div>
	</div>
</div>
	<!--页面底部END-->
	<!-- 引入组件库 -->
	<script src="js/vue.js"></script>
	<script src="https://cdn.bootcss.com/element-ui/2.5.4/index.js"></script>
	<script src="js/axios.js"></script>
	<script src="js/moment.min.js"></script>
<script>
		Vue.filter("dateFilter",function (date, formatPattern) {
			return moment(date).format(formatPattern || "YYYY-MM-DD HH:mm:ss")
        })
		let app = new Vue({
			el: '#app',
			data() {
				return {
				    datemenus:[], //时间菜单列表
					cdate:0, //记录选中菜单的下标
					alltimes:[], //记录每个时间段的倒计时差
					tests:[1,2,3,4,5],
                    goodslist: []
				}
			},
			created:function () {
				this.loadDateMenus();
            },
			methods:{
				//加载时间菜单列表
			    loadDateMenus(){
			        axios.post(`/seckill/goods/dateMenus.do`).then(response=>{
                        this.datemenus=response.data;//查询秒杀时间段
                        //2021-10-14 08:00:00
                        this.searchGoodsList(this.datemenus[0]);//查询第一个时间段的秒杀商品

                        //统计时间差，填充各个时间段倒计时差集合
                        for (var i = 0; i < this.datemenus.length; i++) {
                            if (i == 0) {
                                this.$set(this.alltimes,i,new Date(this.datemenus[1])-new Date());
                            }else {
								this.$set(this.alltimes,i,new Date(this.datemenus[i])-new Date());
                            }
                        }
                        //倒计时操作
                        let interval = window.setInterval(function () {
                            //alert(app.alltimes);
                            //循环时间差数组，并为各个时间差减去1秒
                            for (var i = 0; i < app.alltimes.length; i++) {
                                app.$set(app.alltimes,i,app.alltimes[i]-1000);//让时间差减1秒
                                if (app.alltimes[i] < 1000) {//当出现时间差值小于1秒
                                    window.clearInterval(interval);//停止倒计时
                                    app.loadDateMenus();//重新加载秒杀时段菜单标签页
                                }
                            }
                        },1000);
                    });
				},
                //将毫秒值转换成时分秒
                timeFormat(millisecond){
			        var second=1000;
			        var minute=second*60;
			        var hour=minute*60;

			        var hours=Math.floor(millisecond/hour);//返回小于等于比值的最大整数，即小时数
                    var minutes=Math.floor((millisecond % hour)/minute);//分钟数
                    var seconds=Math.floor((millisecond % minute)/second);//秒数
                    if (hours < 10) {
                        hours="0"+hours;
                    }
                    if (minutes < 10) {
                        minutes="0"+minutes;
                    }
                    if (seconds < 10) {
                        seconds="0"+seconds;
                    }
                    return hours+":"+minutes+":"+seconds;
                },
				//根据秒杀时段查询秒杀商品
				searchGoodsList(time){
			        //转换时间格式，对应redis缓存中存储商品Hash的key值类型
					time=moment(time).format('YYYYMMDDHH');

					//发送异步请求，查询商品
					axios.get(`/seckill/goods/list.do?time=`+time).then(response=>{
                        //将数据绑定到变量上，用以渲染页面
                        app.goodslist=response.data;
                    });
				},
				//跳转到详情页
				targetDetailPage(time,id){
			        time=moment(time).format("YYYYMMDDHH");
			        return '/seckill-item.html?time='+time+"&id="+id;
				}
			}
		})
	</script>
</body>

</html>